package com.dream.net.socket;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class TcpRawPackageDecoder extends ByteToMessageDecoder{

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out){
        byte[] bytes = new byte[buffer.readableBytes()];
        buffer.getBytes(0, bytes);
        String msg = new String(bytes);
        if(msg.endsWith("\n")){
            buffer.clear();
            out.add(msg);
        }
        
    }
}